﻿@{
    var listUser = ViewData["listUser"] as List<KimPhongCRM.Models.sp_Select_Combobox_User_Result>;
    var grid = Html.DevExpress().GridView(settings =>
    {
        settings.Name = "ListNotify";
        settings.CallbackRouteValues = new { Controller = "Notify", Action = "ListNotifyPartial" };

        settings.SettingsPager.Visible = true;
        settings.Settings.ShowGroupPanel = true;
        settings.Settings.ShowFilterRow = true;
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
        settings.SettingsBehavior.AllowSelectByRowClick = true;
        settings.Settings.HorizontalScrollBarMode = ScrollBarMode.Auto;
        settings.Settings.VerticalScrollBarMode = ScrollBarMode.Hidden;

        settings.KeyFieldName = "maLichSu";

        settings.Columns.Add(column =>
        {
            column.FieldName = "ngaySua";
            column.Caption = "Ngày thao tác";
            column.ColumnType = MVCxGridViewColumnType.DateEdit;
            var dateProperties = column.PropertiesEdit as DateEditProperties;
            dateProperties.UseMaskBehavior = true;
            dateProperties.EditFormat = EditFormat.Custom;
            dateProperties.EditFormatString = "dd/MM/yyyy hh:mm tt";
            column.Width = 100;
        });
        //settings.Columns.Add(column =>
        //{
        //    column.FieldName = "table_name";
        //    column.Caption = "TableName";
        //    column.ColumnType = MVCxGridViewColumnType.TextBox;
        //    column.Width = 100;
        //});
        settings.Columns.Add(column =>
        {
            column.FieldName = "loaiSuaDoi";
            column.Caption = "Loại thao tác";
            column.ColumnType = MVCxGridViewColumnType.ComboBox;
            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
            comboBoxProperties.Items.Add("Thêm mới", 1);
            comboBoxProperties.Items.Add("Xóa", -1);
            comboBoxProperties.Items.Add("Thay đổi", 0);
            comboBoxProperties.ValueType = typeof(int);
            column.SetDataItemTemplateContent(c =>
            {

                int edittyppe = Convert.ToInt32(DataBinder.Eval(c.DataItem, "loaiSuaDoi"));
                if(edittyppe==-1)
                {
                    ViewContext.Writer.Write(
                       "<i style=\"color: #FA603D;\" class=\"font-icon-remove-sign\"></i> " + c.Text
                   );
                }
                else if (edittyppe == 1)
                {
                    ViewContext.Writer.Write(
                       "<i style=\"color: #78CD51;\" class=\"font-icon-plus-sign \"></i> " + c.Text
                   );
                }
                else
                {
                    ViewContext.Writer.Write(
                       "<i style=\"color: #FABB3D;\" class=\"font-icon-ok-sign \"></i> " + c.Text
                   );
                }
            });
            column.ReadOnly = true;
            column.Width = 100;
        });  
        
        settings.Columns.Add(column =>
        {
            column.FieldName = "nguoiSua";
            column.Caption = "Người thao tác";
            column.ColumnType = MVCxGridViewColumnType.ComboBox;
            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
            foreach(var value in listUser)
            {
                comboBoxProperties.Items.Add(value.UserName, value.UserId);
            }
            comboBoxProperties.ValueType = typeof(Guid);
            column.ReadOnly = true;
            column.Width = 100;
        });     
        settings.Columns.Add(column =>
        {
            column.FieldName = "noiDung";
            column.Caption = "Nội dung";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
            column.Width = System.Web.UI.WebControls.Unit.Percentage(100);
            column.SetDataItemTemplateContent(c =>
            {
                string html = String.Format("{0}", DataBinder.Eval(c.DataItem, "noiDung"));
                if (html == "") { html = "Không rõ nội dung thao tác"; }
                ViewContext.Writer.Write(html);
            });
        });

    });
    if (ViewData["EditError"] != null)
    {
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}
@grid.Bind(Model).GetHtml()